from sqlalchemy import select

from src.core.models.dto import CategoryDTO
from src.database.converters.category import convert_db_model_to_category_dto
from src.database.exception_mapper import exception_mapper
from src.database.models import Category
from src.database.repositories.base import SQLAlchemyRepo


class CategoryReaderImpl(SQLAlchemyRepo):
    @exception_mapper
    async def get_categories(self) -> list[CategoryDTO]:
        """Получаем зоны доставки"""

        res = await self._session.scalars(select(Category))
        categories: list[Category] = list(res)

        return [convert_db_model_to_category_dto(category) for category in categories]
